/*
 * Copyright (c) 2018-2999 九五云信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 */

package com.yami.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.bean.model.ShopRenovation;
import com.yami.shop.dao.ShopRenovationMapper;
import com.yami.shop.service.ShopRenovationService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Objects;

/**
 * 店铺装修信息
 *
 * @author lhd
 * @date 2021-01-05 11:03:38
 */
@Service
@AllArgsConstructor
public class ShopRenovationServiceImpl extends ServiceImpl<ShopRenovationMapper, ShopRenovation> implements ShopRenovationService {

    private final ShopRenovationMapper shopRenovationMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateToHomePage(Long id, Integer homeStatus, Long shopId) {
        if(Objects.equals(homeStatus,0)){
            update(new LambdaUpdateWrapper<ShopRenovation>().set(ShopRenovation::getHomeStatus,0).eq(ShopRenovation::getHomeStatus,1)
                    .eq(ShopRenovation::getShopId,shopId));
            update(new LambdaUpdateWrapper<ShopRenovation>().set(ShopRenovation::getHomeStatus,1).eq(ShopRenovation::getRenovationId,id));
        }else{
            update(new LambdaUpdateWrapper<ShopRenovation>().set(ShopRenovation::getHomeStatus,0).eq(ShopRenovation::getRenovationId,id));
        }
    }
}
